﻿using AiXiu.BLL;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiXiu.WebStite
{
    public partial class Play : System.Web.UI.Page
    {
        public string VideoId;
        public int UserId;
        public TBvideos Video;
        public TBUsers Author;
        public GetPlayInfoResult playInfo;
        public bool IsLike = false;
        public long LikeCount = 0;
        public long DiscussCount = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //判断是否有视频Id 有：就播放 无：就跳转到Default.aspx界面
                if (Request.QueryString["id"] == null) { Response.Redirect("Default.aspx"); return; }

                this.VideoId = Request.QueryString["id"];
                IVideoManager videoManager = new VideoManager();
                this.Video = videoManager.GetVideoByVideoId(this.VideoId).ReadResult();
                this.Author = Video.TBUsers;
                this.playInfo = videoManager.InitPlay(VideoId).ReadResult();
                TBUsers s = IdentityManager.ReadUser();
                UserId = s.Id;

                //点赞
                ILikeManager likeManager = new LikeManager();
                this.IsLike = likeManager.IsLike(VideoId, UserId);
                this.LikeCount = likeManager.Count(VideoId);
                //评论
                IDiscussManager discussManager = new DiscussManager();
                this.DiscussCount = discussManager.Count(VideoId);
            }
        }
    }
}